//
//  UICollisonViewController.swift
//  Animator
//
//  Created by liu guoqiang on 16/9/9.
//  Copyright © 2016年 liu guoqiang. All rights reserved.
//

import UIKit

class UICollisonViewController: UIViewController {
    @IBOutlet weak var ballImageView: UIImageView!
    
    var collision : UICollisionBehavior!
    var animator : UIDynamicAnimator!
    var gravity : UIGravityBehavior!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "碰撞行为"
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        self.animator = UIDynamicAnimator(referenceView: self.view)
        self.gravity = UIGravityBehavior(items: [self.ballImageView])
        let gravityDirection : CGVector = CGVectorMake(0.0, 0.1)
        self.gravity.gravityDirection = gravityDirection
        self.animator.addBehavior(self.gravity)
        
        self.collision = UICollisionBehavior(items: [self.ballImageView])
        self.collision.translatesReferenceBoundsIntoBoundary = true
        self.animator.addBehavior(self.collision)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}
